package com.wm.eduService.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.wm.commonutils.R;
import com.wm.eduService.entity.EduComment;
import com.wm.eduService.entity.EduCourse;
import com.wm.eduService.service.EduCommentService;
import com.wm.servicebase.exceptionhandle.GuliException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author sshdg
 * @since 2020-10-12
 */
@RestController
@RequestMapping("/eduService/comment")
@Api(tags = "评论接口")
//@CrossOrigin
public class EduCommentController {

    @Autowired
    private EduCommentService commentService;

    @ApiOperation("添加评论")
    @PostMapping("/addComment")
    public R addComment(@RequestBody EduComment comment){
        System.out.println(comment);
        if (StringUtils.isEmpty(comment.getMemberId())){
            return R.error().message("请先登录！");
        }
        commentService.save(comment);
        return R.ok();
    }
    @ApiOperation("分页查询评论")
    @GetMapping("getComments/{courseId}/{page}/{size}")
    public R getComments(@PathVariable long page,
                         @PathVariable long size,
                         @PathVariable String courseId){
        System.out.println(courseId);
        Page<EduComment> commentPage  = new Page<>(page, size);
        Map<String, Object> map = commentService.pageComment(commentPage, courseId);

        return R.ok().data(map);
    }

}

